<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/component/commonTagLib.jsp" %>
<!DOCTYPE html>
<html>
<head>
    <title>生产企业</title>
    <%@ include file="/WEB-INF/component/commonCSS.jsp" %>
</head>
<body class="skin-blue-light sidebar-mini fixed skin-blue-light-frame">
<input type="hidden" name="projId" id="projId" value="${projId}"/>							
    <section class="content-header">
        <h1>已添加生产企业</h1>
        <ol class="breadcrumb">
            <li><a href="${ctx}/home.jsp"><i class="fa fa-home"></i>首页</a></li>
			<li class="active">药品招标管理</li>
            <li class="active">采购项目管理</li>
            <li class="active">查看</li>
        </ol> 
    </section>
    
    <section class="content">
        <div class=" box box-success">
            <div class="box-body">
                <div class="form-inline"> 
                    <div class="form-group form-group-xs">
                        <label for="searchCompCode">企业编码：</label>
                        <input class="form-control" type="text" id="scompCode" placeholder="企业编码" maxlength="30" />
                    </div>
                    <div class="form-group form-group-xs">
                        <label for="searchCompName">企业名称：</label>
                        <input class="form-control" type="text" id="scompName" placeholder="企业名称" maxlength="127" />
                    </div>
                    <div class="form-group form-group-xs">
                        <label for="searchCompShortName">企业简称：</label>
                        <input class="form-control" type="text" id="sName" placeholder="企业简称" maxlength="127" />
                    </div>
                    
                    <button type="button" class="btn btn-success btn-sm" onclick="search();">查询</button>
                </div>
            </div>
        </div>
        
        <table class="jqgrid" id="gridlist"></table>
        <div id="gridpage"></div>
        
        <div class=" box box-warning bottongroup">
        	 <label id="batchEnable" class="btn btn-default btn-sm" onclick="batchChangeStatus(1)">启  用</label>
             <label id="batchDisable" class="btn btn-default btn-sm" onclick="batchChangeStatus(0)">停  用</label>
             <a href="${ctx }/bidProject/toList.html" class="btn btn-default btn-sm">返  回</a>
        </div>
    </section>
    <%@ include file="/WEB-INF/component/commonJS.jsp" %>
    <script type="text/javascript">
    //启用、停用
    	function changeStatus(projDelId, compId, status) {
    		var msg = "";
 			if (status == "0") {
 				msg = "停用";
 			} else if (status == "1") {
 				msg = "启用";
 			}
    		$.HN.message.confirm('确定'+msg+'吗？', '', '').on(function (e) {
          		 if(e){
    		$.post("${ctx }/bidProject/changeCompStatus.html", {
    			"projDelId":projDelId,
				"projId":"${projId}",
				"compId":compId,
    			"status":status
    		}, function(result) {
    			if (result) {
    				$("#gridlist").jqGrid('setGridParam',{  
            	        datatype:'json'
            	    }).trigger("reloadGrid");
					$.HN.message.alert("操作成功！", "消息", "success");
    			} else {
    				$.HN.message.alert("操作失败！", "消息", "error");
    			}
    		}, "json")
    	 }
		 
	 });
    	}
           //批量启用、停用
    	function batchChangeStatus(status) {
    		var msg = "";
 			if (status == "0") {
 				msg = "停用";
 			} else if (status == "1") {
 				msg = "启用";
 			}
    		var rowIds = $("#gridlist").jqGrid("getGridParam", "selarrrow") || [];
    		if (rowIds.length <= 0) {
    			$.HN.message.alert("请选择要操作的行！", "消息", "error");
    			return;
    		}
    		$.HN.message.confirm('确定'+msg+'吗？', '', '').on(function (e) {
       		 if(e){
    		var list = [];
    		for (var i=0; i<rowIds.length; i++) {
    			var rowdata = $("#gridlist").jqGrid('getRowData', rowIds[i]);
    			var rowId = rowdata.projDelId;
				var compId = rowdata.compId;
    			list.push({"projDelId":rowId, "status":status,"projId":"${projId}", "compId":compId,});
    		}
    		$.post("${ctx }/bidProject/batchChangeCompStatus.html", {
    			"array" : json.jsonToString(list)
    		}, function(result) {
    			if (result) {
					$.HN.message.alert("操作成功！", "消息", "success");
    				var curpage = $("#gridlist").jqGrid('getGridParam', 'page');
    				$("#gridlist").jqGrid('setGridParam',{  
            	        datatype:'json'
            	    }).trigger("reloadGrid");
    			} else {
    				$.HN.message.alert("操作失败！", "消息", "error");
    			}
    		}, "json")
       		 }
			 
			 });
    	}

    	function search() {
    		
    		var scompCode = $("#scompCode").val();
    		var scompName = $("#scompName").val();
    		var sName = $("#sName").val();
    		$("#gridlist").jqGrid("clearGridData");
    		$("#gridlist").jqGrid('setGridParam',{  
    			url:"${ctx}/bidProject/getAddedBidProjectCompsList.html",
    			mtype: "POST",
    	        datatype:'json',
    	        postData:{"scompCode":scompCode, "scompName":scompName, "sName":sName},
    	        page : 1
    	    }).trigger("reloadGrid"); //重新载入  
    	}
    
        $(function () {
            
            $("#gridlist").jqGrid({
                url: "${ctx}/bidProject/getAddedBidProjectCompsList.html",
                mtype: "post",
                datatype: "json",
                postData: {"projId" : "${projId}"},
                autowidth: true,
                height: 270,
                colNames: ['projDelId','compId','企业编码', '企业名称', '企业简称', '所属集团', '状态'],
                colModel: [
					{ name: 'projDelId',hidden:true, width: 10, align:"center", sortable: false},
					{ name: 'compId',hidden:true, width: 10, align:"center", sortable: false},
                    { name: 'compCode', width: 10 , align:"center",sortable: false,
                    	formatter:function(cellvalue, options, row){ 
                    		return "<a href=\"javascript:$.HN.dialog.opendialog('"+cellvalue+"','企业详情','${ctx}/stdCompinfo/toStdCompinfoDetailJsp.html?compCodeDetail="+cellvalue+"','800px','400px',function operResult(val){return operResult;})\">"+cellvalue+"</a>"
                    				}
                    },
                    { name: 'compName', width: 10, align:"center", sortable: false },
                    { name: 'compShortName', width: 10, align:"center", sortable: false},
                    { name: 'compGroupName', width: 10, align:"center", sortable: false},
                    { name: 'statusText', width: 10, align:"center", sortable: false}
                ],
                rowNum: 0,
                rowList: [10, 20, 50, 100],
                rownumbers: true,
                //pager: "#gridpage",
                multiselect: true, 
                viewrecords: true,
                caption: "${name}-已添加配送企业",
                jsonReader: {
                    id: "projDelId"
                }
            });
            
            $("#gridlist").jqGrid('navGrid', '#gridpage', { add: false, edit: false, del: false, search: false, refresh: false });
            $(window).trigger("resize");
            
        });
    </script>
</body>
</html>